package com.david.func_test

import android.app.Activity
import android.app.Application
import android.os.Bundle
import com.david.func_test.activity.LeakTestActivity

class FuncTestApplication: Application() {
    override fun onCreate() {
        super.onCreate()
        registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks{
            override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
                if (activity is LeakTestActivity) {
                    list.add(activity)
                }
            }

            override fun onActivityStarted(activity: Activity) {

            }

            override fun onActivityResumed(activity: Activity) {

            }

            override fun onActivityPaused(activity: Activity) {

            }

            override fun onActivityStopped(activity: Activity) {

            }

            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

            }

            override fun onActivityDestroyed(activity: Activity) {
                if (activity is LeakTestActivity) {
                    list.remove(activity)
                }
            }

        })
    }

    companion object{
        val list = ArrayList<Activity>()
    }
}